<!-- 收支分析 -->
<template>
    <base-breadcrumb>
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card>
             <div class="table-operator">
                <!-- <a-button v-btnPermission="'bm_012_add_01'" type="primary" icon="plus" @click="handleUpdate('edit', {})">编辑</a-button> -->
            </div>
            <list-table ref="table" size="default" rowKey="id" :columns="columns" :request="loadData" :alert="true"
                :export-config="{
                        use: true,
                        select: '收支分析',
                        all: '收支分析'
                    }"
                        :exportPermission="{ select: 'bm_040_exp_03', all: 'bm_040_exp_03' }"
                      :statistics-config="{ use: true, total, temp }"
                show-size-changer show-quick-jumper showPagination="auto"
                 >
                 <!-- :exportPermission="{select: 'bm_012_edi_02',all: 'bm_012_edi_02'}" -->
                <span slot="operation" slot-scope="text, record">
                    <MoreButton>
                    <a @click="handleUpdate('looks', record)"
                        v-btnPermission="'bm_040_loo_02'">查看</a>
                    <a @click="handleUpdate('edit', record)" 
                        v-btnPermission="'bm_040_edi_01'" v-if="(record.auditStatus == 'DRAFT')&&hideBuquBtn()">编辑</a>
                       
                    </MoreButton>
                </span>
            </list-table>
            <!-- <ApprovalDetails
              :title="'审批详情'"
              :business-id="businessId"
              :visible="visibleApprove"
              @cancel="visibleApprove = false"
              @confirm="visibleApprove = false"
      /> -->
        </a-card>
    </base-breadcrumb>
</template>
<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 分包商
// import ApprovalDetails from '@/components/approvalDetails'
import { STable } from '@/components'
import listStatus from '@/components/list_status/list_status'
import { getcount, getList } from '@/api/businessAffairs/szAnalysis'
import { typeListApproval3 } from '@/utils/util'
const columns = [
    {
        title: '序号',
        width: 80,
        dataIndex: 'index',
        customRender() {
            return arguments[2] + 1
        },
    },
    {
        title: '名称',
        dataIndex: 'name',
    },
    {
        title: '分公司',
        dataIndex: 'branchComName',
    },
    {
        title: '项目名称',
        dataIndex: 'projectName',
    },
    {
        title: '累计预计总收入（不含税）(万元)',
        dataIndex: 'budgetAnalysisOfAmountDTO.expectedIncome',
    },
    {
        title: '累计预计总成本（不含税）(万元)',
        dataIndex: 'budgetAnalysisOfAmountDTO.expectedCost',
    },
    {
        title: '累计销项税(万元)',
        dataIndex: 'budgetAnalysisOfAmountDTO.outputTax',
    },
    {
        title: '累计进项税(万元)',
        dataIndex: 'budgetAnalysisOfAmountDTO.inputTax',
    },
    {
        title: '累计附加税(万元)',
        dataIndex: 'budgetAnalysisOfAmountDTO.additionalTax',
    },
    {
        title: '累计应交税金(万元)',
        dataIndex: 'budgetAnalysisOfAmountDTO.payableTax',
    },
    {
        title: '累计利润额(含税)(万元)',
        dataIndex: 'budgetAnalysisOfAmountDTO.profitAmount',
    },
    {
        title: '累计利润率(含税)(%)',
        dataIndex: 'budgetAnalysisOfAmountDTO.profitMargin',
    },
    {
        title: '工程计量确认率(%)',
        dataIndex: 'projectMeasureConfirmRate',
    },
    {
        title: '填报人',
        dataIndex: 'informant',
    },
    {
        title: '填报时间',
        dataIndex: 'informantDate',
    },
    {
        title: '状态',
        dataIndex: 'auditStatusName',
    },
    {
        title: '操作',
        dataIndex: 'operation',
        width: '170px',
        scopedSlots: { customRender: 'operation' },
    },
]
const searchArr = [
    {
        name: '所属单位',
        valueKey: 'searchQuery',
        type: OrgTreeSelect,
    },
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany,
    // },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject,
    // },
    // {
    //     name: '会议名称',
    //     value: 'meetingName',
    //     type: 'input',
    // },
    {
        name: '月份',
        value: 'month',
        type: 'month',
    },
    {
        name: '填报人',
        value: 'informant',
        type: 'input',
    },
    {
        name: '填报时间',
        value: 'informantTime',
        type: 'dateRange',
    },
    {
        name: '状态',
        value: 'auditStatus',
        type: 'select',
        data: typeListApproval3,
    }
]

export default {
    name: 'as' + Date.now(),
    components: {
        STable,
        listStatus,
        // ApprovalDetails,
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            total:{},
            countList:{},
            visibleApprove: false,
            temp: () => {
            return (
                <span style="margin-right: 12px">
                累计预计总收入(不含税)(万元)：<span class="totalNum">{this.countList.accExpectedIncome }  </span>
                累计预计计总成本(不含税)(万元)：<span class="totalNum">{this.countList.accexpectedCost }  </span>
                累计销项税(万元)：<span class="totalNum">{this.countList.accOutputTax }</span>
                累计进项税(万元)：<span class="totalNum">{this.countList.accInputTax }  </span>  
                累计附加税(万元)：<span class="totalNum">{this.countList.accAdditionalTax }  </span>  
                累计应交税金(万元)：<span class="totalNum">{this.countList.accPayableTax}  </span>  
                累计利润额(万元)：<span class="totalNum">{this.countList.accProfitAmount }  </span>  
                累计利润率(%)：<span class="totalNum">{this.countList.accProfitMargin }  </span>  
                工程计量确认率(%)：<span class="totalNum">{this.countList.accMeasureConfirmRate }  </span>  
                </span>
            )
          },
            queryParam: {},
            loadData: async (parameter) => {
                this.queryParam = { ...this.queryParam }
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                this.getcountList(requestParameters)
                const  res = await getList(requestParameters)
                res.data.forEach(item => {
                    if(item.auditStatus=='DRAFT'){
                        item.auditStatusName='待提交'
                    }else {
                        item.auditStatusName='已提交'
                    }
                  if(!item.informant) {
                    item.informantDate = ''
                  }
                });
                return new Promise((resolve, reject) => {
                        resolve(res)
                })
            },
            
        }
    },
    mounted() {
        // this.getSearchListReq()
    },
    methods: {
        handleApproveDetail(record) {
        this.visibleApprove = true
        this.businessId = record.id
      },
      getcountList(requestParameters){
        getcount(requestParameters).then(res=>{
            if (res.code === 200) {
                this.countList=res.data
              }
          })
        },
        //搜索
        search(val = {}) {
            this.queryParam = {
                ...val,
                // typeId: 4,

            //    finishedBeginDate:
            //          (val.finishedDate && val.finishedDate.length && val.finishedDate[0].format('YYYY-MM-DD')) || void 0,
            //    finishedEndDate:
            //         (val.finishedDate && val.finishedDate.length && val.finishedDate[1].format('YYYY-MM-DD')) || void 0,
                informantBeginTime:
                    (val.informantTime && val.informantTime.length && val.informantTime[0].format('YYYY-MM-DD')) || void 0,
                informantEndTime:
                    (val.informantTime && val.informantTime.length && val.informantTime[1].format('YYYY-MM-DD')) || void 0,
            }

            console.log("queryParam",this.queryParam)

            this.$refs.table.refresh(true)
        },

        // 处理操作
        async handleUpdate(type, data = {}) {
           
                this.$router.push({
                     name: 'szAnalysisEdit',
                     query: {
                        id: data.id || '',
                        pageType: type,
                        projectId: data.projectId
                    },
                 })
        },
    },
}
</script>
